package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.entity.Activity;
import com.qk.management.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 活动管理控制器
 *
 * @Author:Mr.m
 * @Date: 2025-10-09 15:54
 * @Description: TODO
 */
@Slf4j
@RestController
@RequestMapping("/activities")
public class ActivityController {
    @Autowired
    private ActivityService activityService;

    //根据指定类型的查询活动
    @GetMapping("/type/{type}")
    public Result queryActivityByType(@PathVariable Integer type){
        log.info("查询活动,参数:type:{}",type);
        List<Activity> activities = activityService.queryActivityByType(type);
        return Result.success(activities);
    }

    //删除活动
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        log.info("删除活动id:{}",id);
        activityService.deleteById(id);
        return Result.success();
    }

    //修改活动内容
    @PutMapping
    public Result update(@RequestBody Activity activity) {
        log.info("修改活动:{}", activity);
        activityService.update(activity);
        return Result.success();
    }

    //根据id查询活动（数据回显）
    @GetMapping("/{id}")
    public Result queryActivityById(@PathVariable Integer id) {
        log.info("查询活动,参数:id:{}", id);
        Activity activity = activityService.queryActivityById(id);
        return Result.success(activity);
    }

    //新增活动
    @PostMapping
    public Result addActivity(@RequestBody Activity activity) {
        log.info("新增活动:{}", activity);
        activityService.addActivity(activity);
        return Result.success();
    }

    //分页查询所有活动
    @GetMapping
    public Result queryActivityByPage(
            @RequestParam(name = "channel", required = false) Integer channel,
            @RequestParam(name = "type", required = false) Integer type,
            @RequestParam(name = "status", required = false) Integer status,
            @RequestParam(name = "page", defaultValue = "1") Integer page,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        log.info("查询活动,参数:name:{},status:{},page:{},pageSize:{}", channel, type, status, page, pageSize);
        PageResult<Activity> pageResult = activityService.page(channel, type, status, page, pageSize);
        return Result.success(pageResult);
    }
}
